package liumengbaio.lolzhangyoubao.Activity.Fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.Adapter.ViewPagerAdapter;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/8/24.
 */
public class FragmentVideo extends Fragment {


    private TabLayout video_tl;
    private ViewPager video_vp;

    private List<String> list_tabNames;
    private List<Fragment> list_vp;
    private ViewPagerAdapter adapter;
    private FragmentVideo_commentary commentary;
    private FragmentVideo_competition competition;
    private FragmentVideo_recreation recreation;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_video, null);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView(getView());
        initData();
    }

    private void initView(View view) {
        video_tl = (TabLayout) view.findViewById(R.id.video_tl);
        video_vp = (ViewPager) view.findViewById(R.id.video_vp);
        commentary = new FragmentVideo_commentary();
        competition = new FragmentVideo_competition();
        recreation = new FragmentVideo_recreation();
        list_vp = new ArrayList<>();
        list_tabNames = new ArrayList<>();

    }

    private void initData() {
        list_tabNames.add("娱乐");
        list_tabNames.add("解说");
        list_tabNames.add("赛事");
        list_vp.add(recreation);
        list_vp.add(commentary);
        list_vp.add(competition);

        adapter = new ViewPagerAdapter(getFragmentManager(), list_tabNames, list_vp);
        video_vp.setAdapter(adapter);
        video_tl.setupWithViewPager(video_vp);
    }
}
